package com.log.blog_backend.service.impls;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.log.blog_backend.common.Result;
import com.log.blog_backend.entity.UserInfo;
import com.log.blog_backend.mapper.UserInfoMapper;
import com.log.blog_backend.service.UserInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.log.blog_backend.utils.TokenUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author blog
 * @since 2023-01-01
 */
@Service
public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo> implements UserInfoService {

    @Autowired
    TokenUtil tokenUtil;

    @Autowired
    UserInfoMapper userInfoMapper;
    @Override
    public Result getUserInfo(HttpServletRequest httpServletRequest) {

        String userId = tokenUtil.getUserIdByToken(httpServletRequest);
        //由userId获取userInfo数据 返回
        QueryWrapper<UserInfo>queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("userId",userId);
        UserInfo userInfo = userInfoMapper.selectOne(queryWrapper);
        return Result.ok(userInfo);
    }


}
